/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: jse2302 - StringBuilderDemo
 * <p>Powered by webrx On 2023-06-20 09:41:09
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        StringBuilder s1 = new StringBuilder("abc");
        s1.reverse();
        System.out.println(s1.toString().toUpperCase());

        StringBuffer s2 = new StringBuffer("123");
        s2.deleteCharAt(0);
        s2.delete(1, 2);
        s2.insert(0, 987);  //9872
        System.out.println(s2.reverse().append(",java").toString().toUpperCase());

        StringBuilder sbu = new StringBuilder();
        sbu.append("123");
        sbu.delete(0, sbu.length());
        sbu.append("hello,java");
        System.out.println(sbu.length());
        System.out.println(sbu.substring(sbu.lastIndexOf(",") + 1, sbu.length() - 2));


        //String 和 StringBuilder1 转换
        String str = "hello";
        System.out.println(str);
        StringBuilder strsu = new StringBuilder(str);
        str = strsu.reverse().append(String.format(",时间：%tF %<tT %<tA %<tB %<tp",System.currentTimeMillis())).toString().toUpperCase();
        System.out.println(str);
    }
}
